//
//  MyobligationCell.m
//  spotrs
//
//  Created by sky on 16/5/18.
//  Copyright © 2016年 TZ. All rights reserved.
//

#import "MyobligationCell.h"

@implementation MyobligationCell
{
    UILabel *_titlelbl;
    UILabel *_explainlbl;
    UILabel *_moneyexplainlbl;
    UILabel *_eventlbl;
    UILabel *_datelbl;
    UILabel *_moneylbl;
    UIImageView *_finishvi;
}

-(void)setSource:(NSString *)source{
    _source = source;
    if ([self.source isEqualToString:@"1"]) {
        UIButton *appld = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 15 - 2 * 50 - 10, _moneylbl.frame.origin.y + 13/2 - 10, 50, 20)];
        [appld setBackgroundColor:[UIColor orangeColor]];
        appld.tag = 1024;
        [appld addTarget:self action:@selector(clickToSelect:) forControlEvents:UIControlEventTouchUpInside];
        [appld setTitle:@"支付" forState:UIControlStateNormal];
        appld.titleLabel.font = [UIFont systemFontOfSize:13];
        appld.layer.cornerRadius = 3;
        [self.contentView addSubview:appld];
        
        
        UIButton *deleted = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 15 - 50, _moneylbl.frame.origin.y + 13/2 - 10, 50, 20)];
        [deleted setBackgroundColor:[UIColor clearColor]];
        [deleted setTitle:@"取消" forState:UIControlStateNormal];
        deleted.titleLabel.font = [UIFont systemFontOfSize:13];
        [deleted setTitleColor:[LCCommon getColor:@"ebebeb"] forState:UIControlStateNormal];
        [deleted addTarget:self action:@selector(clickToSelect:) forControlEvents:UIControlEventTouchUpInside];
        deleted.layer.cornerRadius = 3;
        deleted.layer.borderColor = [LCCommon getColor:@"ebebeb"].CGColor;
        deleted.tag = 1025;
        deleted.layer.borderWidth = .5;
        [self.contentView addSubview:deleted];
    }else{
        UIButton *off = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 15 - 20, 45/2 - 10 + 5, 20, 20)];
        [off setBackgroundColor:[LCCommon getColor:@"999999"]];
        [off addTarget:self action:@selector(btnPress) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:off];
    }
}


-(void)setTextStr:(NSString *)textStr{
    _textStr = textStr;
    if ([_textStr isEqualToString:@"1"]) {
        _finishvi.alpha = 1;
    }
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self buildLayout];
    }
    return self;
}

-(void)buildLayout{
    UIView *bgview = [[UIView alloc]initWithFrame:CGRectMake(0, 5, SCREEN_WIDTH, 45)];
    bgview.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:bgview];
    
    _titlelbl = [self LabelWithRect:CGRectMake(15, 45/2 - 15/2, SCREEN_WIDTH - 15, 15) textColor:[UIColor blackColor] textstr:@"网球 - 约球" textfont:15 textstyle:NSTextAlignmentLeft];
    [bgview addSubview:_titlelbl];
    
    [self makeLinewithRect:CGRectMake(0, 44.5, SCREEN_WIDTH, .5) Color:[LCCommon getColor:@"ebebeb"] addview:bgview];
    
    [self makeLinewithRect:CGRectMake(0, 525/3 - .5, SCREEN_WIDTH, .5) Color:[LCCommon getColor:@"ebebeb"] addview:self.contentView];
    
    CGFloat space = (525/3 - 45 - 13 * 5 )/6;
    _explainlbl = [self LabelWithRect:CGRectMake(15, space + 50, SCREEN_WIDTH - 15, 13) textColor:[LCCommon getColor:@"999999"] textstr:@"奥林匹克中心  初级" textfont:13 textstyle:NSTextAlignmentLeft];
    [self.contentView addSubview:_explainlbl];
    
    UILabel *feiyong = [self LabelWithRect:CGRectMake(15, _explainlbl.frame.origin.y + 13 + space, 13 * 2 + 13, 13) textColor:[LCCommon getColor:@"999999"] textstr:@"费用 :" textfont:13 textstyle:NSTextAlignmentLeft];
    [self.contentView addSubview:feiyong];
    
    UILabel *huodong = [self LabelWithRect:CGRectMake(15, feiyong.frame.origin.y + 13 + space, 13 * 4 + 13, 13) textColor:[LCCommon getColor:@"999999"] textstr:@"活动方式 :" textfont:13 textstyle:NSTextAlignmentLeft];
    [self.contentView addSubview:huodong];
    
    UILabel *shijian = [self LabelWithRect:CGRectMake(15, huodong.frame.origin.y + 13 + space, 13 * 4 + 13, 13) textColor:[LCCommon getColor:@"999999"] textstr:@"截止时间 :" textfont:13 textstyle:NSTextAlignmentLeft];
    [self.contentView addSubview:shijian];
    
    UILabel *jine = [self LabelWithRect:CGRectMake(15, shijian.frame.origin.y  + 13 + space, 13 * 2 + 13 , 13) textColor:[LCCommon getColor:@"999999"] textstr:@"金额 :" textfont:13 textstyle:NSTextAlignmentLeft];
    [self.contentView addSubview:jine];
    
    _moneyexplainlbl = [self LabelWithRect:CGRectMake(feiyong.frame.origin.x + feiyong.frame.size.width, feiyong.frame.origin.y, SCREEN_WIDTH - (feiyong.frame.origin.x + feiyong.frame.size.width), 13) textColor:[LCCommon getColor:@"999999"] textstr:@"AA制" textfont:13 textstyle:NSTextAlignmentLeft];
    [self.contentView addSubview:_moneyexplainlbl];
    
    _eventlbl = [self LabelWithRect:CGRectMake(huodong.frame.origin.x + huodong.frame.size.width, huodong.frame.origin.y, SCREEN_WIDTH - (huodong.frame.origin.x + huodong.frame.size.width), 13) textColor:[LCCommon getColor:@"999999"] textstr:@"单打" textfont:13 textstyle:NSTextAlignmentLeft];
    [self.contentView addSubview:_eventlbl];
    
    _datelbl = [self LabelWithRect:CGRectMake(shijian.frame.origin.x + shijian.frame.size.width, shijian.frame.origin.y, SCREEN_WIDTH - (shijian.frame.origin.x + shijian.frame.size.width), 13) textColor:[LCCommon getColor:@"999999"] textstr:@"2015-4-8" textfont:13 textstyle:NSTextAlignmentLeft];
    [self.contentView addSubview:_datelbl];
    
    _moneylbl = [self LabelWithRect:CGRectMake(jine.frame.origin.x + jine.frame.size.width, jine.frame.origin.y, SCREEN_WIDTH - (jine.frame.origin.x + jine.frame.size.width), 13) textColor:[LCCommon getColor:@"999999"] textstr:@"170.0元" textfont:13 textstyle:NSTextAlignmentLeft];
    [self.contentView addSubview:_moneylbl];
    
    _finishvi = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 35 - 13 * 7, 45 + ((525/3 - 45)/2 - 13 * 7/2), 13 * 7, 13 * 7)];
    _finishvi.layer.cornerRadius = 13 * 7 / 2;
    _finishvi.backgroundColor = [LCCommon getColor:@"999999"];
    _finishvi.alpha = 0;
    [self.contentView addSubview:_finishvi];
    
}

-(void)btnPress{
    if (self.ActionPreviewPressToSelelct)
    {
        self.ActionPreviewPressToSelelct();
    }
}

- (void)clickToSelect:(UIButton *)sender
{
    if (self.ActionPreviewClickToSelelct)
    {
        self.ActionPreviewClickToSelelct(sender);
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(UIView *)makeLinewithRect:(CGRect)rect Color:(UIColor *)color addview:(UIView *)vi{
    UIView *line = [[UIView alloc]initWithFrame:rect];
    line.backgroundColor = color;
    [vi addSubview:line];
    return line;
}


-(UILabel *)LabelWithRect:(CGRect)rect textColor:(UIColor *)color textstr:(NSString *)str textfont:(int)font textstyle:(NSTextAlignment)aligment{
    UILabel *label = [[UILabel alloc] initWithFrame:rect];
    label.textColor = color;
    label.text = str;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = aligment;
    label.numberOfLines = 0;
    return label;
}



@end
